package coms.fourthirty.emm;

import coms.fourthirty.emm.resources.EMSResources;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.PopupWindow;
import android.widget.Toast;

/**
 * The main screen for the Pharos Employee Management System
 * @author crgk
 *
 */
public class EMSHome extends Activity {
	private String username;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle grundle) {
		super.onCreate(grundle);
		setContentView(R.layout.home);

		username = EMSResources.username;
		Bundle extras = getIntent().getExtras();
		
		if(extras != null && extras.getBoolean("coms.fourthirty.emm.hoursSubmitted"))
		{
			Toast.makeText(getBaseContext(), "Hours submitted", Toast.LENGTH_SHORT).show();
		}
	}

	public void goToMessages(View view) {
		Intent i = new Intent(EMSHome.this, EMSMessages.class);
		// i.putExtra("coms.fourthirty.emm.username", username);
		startActivity(i);
	}

	

	public void clockIn(View view) {
//		LayoutInflater inflater = (LayoutInflater) this
//				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//		PopupWindow pw = new PopupWindow(inflater.inflate(
//				R.layout.popup_clock, null, false), 300, 300, true);
//		pw.showAtLocation(this.findViewById(R.id.home), Gravity.CENTER, 0, 0);
		// swapButtons(R.id.button_clockin, R.id.button_clockout);
		findViewById(R.id.frame_clock).setVisibility(View.VISIBLE);
	}

	public void clockOut(View view) {
		swapButtons(R.id.button_clockout, R.id.button_clockin);
	}

	public void submitHours(View view) {
		//TODO: send to server
		findViewById(R.id.frame_clock).setVisibility(View.INVISIBLE);
		Toast.makeText(getBaseContext(), "Hours submitted", Toast.LENGTH_SHORT).show();
	}
	
	private void swapButtons(int id1, int id2) {
		findViewById(id1).setVisibility(View.INVISIBLE);
		findViewById(id2).setVisibility(View.VISIBLE);
	}

	public void goToTimesheet(View view) {
		Intent i = new Intent(EMSHome.this, EMSTimesheet.class);
		// i.putExtra("coms.fourthirty.emm.username", username);
		startActivity(i);
	}

	public void goToSchedule(View view) {
		Intent i = new Intent(EMSHome.this, EMSSchedule.class);
		// i.putExtra("coms.fourthirty.emm.username", username);
		startActivity(i);
	}
}